export const DrawIcon = {
	onSetup: (opts) => {
		const state = {};

		state.icon = opts.icon || "draw-icon";
		state.iconSize = opts.iconSize;

		return state;
	},

	onClick: function (state, e) {
		const point = this.newFeature({
			type: "Feature",
			properties: {
				icon: state.icon,
				iconSize: state.iconSize,
			},
			geometry: {
				type: "Point",
				coordinates: [e.lngLat.lng, e.lngLat.lat],
			},
		});

		this.addFeature(point);

		this.map.fire("draw.create", {
			features: [point.toGeoJSON()],
			mode: "draw_icon",
		});

		this.changeMode("simple_select");
	},

	toDisplayFeatures: (state, geojson, display) => {
		display(geojson);
	},
};
